﻿<%@ WebHandler Language="C#" Class="PaperInfo" %>

using System;
using System.Web;
using Newtonsoft.Json;
using System.Data;
using Common;
using System.Text;

public class PaperInfo : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.Charset = "UTF-8";
        context.Response.ContentType = "text/plain";

        string strResult = "";
        DataTable dtResult = new DataTable();
        string action = context.Request.QueryString["action"];
        string userid = context.Request.QueryString["userid"] != null ? context.Request.QueryString["userid"] : "";
        string depart = context.Request.QueryString["department"] != null ? context.Request.QueryString["department"] : "";
        switch (action)
        {
            case "getpaperlist":
                string swhere = "";
                if (depart == "0")
                    swhere = " DepartmentId='7' ";//如果是0就是获取职教科所有的试卷列表
                else swhere = " DepartmentId='29' ";//否则就是获取运用科所有的试卷列表
                DataSet dsList = new BLL.pe_paperMa().GetList(0, swhere, " createTime desc");
                if (dsList != null)
                    if (dsList.Tables.Count > 0)
                        if (dsList.Tables[0].Rows.Count > 0)
                        {
                            dtResult = dsList.Tables[0];
                        }
                break;
            case "getpaperdetail":
                string paperid = context.Request.QueryString["paperid"] != null ? context.Request.QueryString["paperid"] : "";
                string strsql = " select paperBh,case when a.tix=0 then '判断题' else case when a.tix=1 then '选择题' else case when a.tix=2 then '填空题' else case when a.tix=3 then '简答题' else case when a.tix=4 then '综合题' end end end end end  as tix," +
                    " a.tikBH,tikFenZhi,ShiT,'' as ShiTi, case when RightAnswer='Y' then '对' else case when RightAnswer='N' then '错' else RightAnswer end end as RightAnswer,b.bFenzhi from pe_paperDe a " +
                    " left join pe_Tik b on a.tikBH=b.bh " +
                    " where paperBh='"+paperid+"'"; 
                DataSet ds = new BLL.T_Public().Query(strsql);
                if (ds != null)
                    if (ds.Tables.Count > 0)
                        if (ds.Tables[0].Rows.Count > 0)
                        { 
                            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                            { 
                                byte[] bShiT = (byte[])ds.Tables[0].Rows[i]["ShiT"];
                                string sShiT = Encoding.Default.GetString(bShiT);
                                ds.Tables[0].Rows[i]["ShiTi"] = sShiT;
                            }
                            dtResult = ds.Tables[0];
                        }
                break;
        }


        if (dtResult.Rows.Count > 0)
        {
            ReturnMsg rm = new ReturnMsg();
            rm.retcode = 0;
            rm.remark = "获取成功！";
            rm.retdatatable = dtResult;
            rm.retjson = "";
            strResult = rm.retdata;
        }
        else
        {
            ReturnMsg rm = new ReturnMsg();
            rm.retcode = 1;
            rm.remark = "数据不存在！";
            rm.retdatatable = null;
            rm.retjson = "[]";
            strResult = rm.retdata;
        }
        context.Response.Write(strResult);
        context.Response.End(); 




    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}